//============================================================================
// Name        : Merceria.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>
#include "SerialBuffer.h"
#include "ArchivoBloques.h"
using namespace std;



static int escribir() {
	ArchivoBloques file(10, "test");
	SerialBuffer unSerBuff(10);

	char a = 'a';
	int b = 2;

	int c = 65;
	char d = 'U';

	//guardo las cosas en el buffer
	unSerBuff.pack(&a, sizeof(a));
	unSerBuff.pack(&b, sizeof(b));
	//unSerBuff.pack(&e, sizeof(e));
	file.escribirBloque(unSerBuff.getBuffer(), 0);
	unSerBuff.clear();

	unSerBuff.pack(&c, sizeof(c));
	unSerBuff.pack(&d, sizeof(d));
	file.escribirBloque(unSerBuff.getBuffer(), 1);
	unSerBuff.clear();

	return 0;
}

static int leer() {

	ArchivoBloques file(10, "test");
	SerialBuffer unSerBuff(10);

	char a, d;
	int b, c;

	file.leerBloque(unSerBuff.getBuffer(), 0);
	unSerBuff.unpack(&a);
	unSerBuff.unpack(&b);

	cout << a << endl;
	cout << b << endl;

	unSerBuff.clear();
	file.leerBloque(unSerBuff.getBuffer(), 1);


	unSerBuff.unpack(&c);
	unSerBuff.unpack(&d);
	unSerBuff.clear();
	cout << c << endl;
	cout << d << endl;

	return 0;
}

int main() {
	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!

	//return leer();
	return escribir();
}


